<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,util.*,dal.*,model.*, bll.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	int idProject = MiscUtil.getIntUrlParam(request, "idProject");
	boolean hasProject = false;
	String projectName = "Unknown";
	String projectUrl = "";
	//int idProjectTemp=idProject;
	
	if(idProject != Integer.MIN_VALUE)
	{	
		projectName = CacheUtil.getProjectName(idProject);
		projectUrl = "project.jsp?id="+idProject;
		hasProject = true;
	}
// 	else
// 	{
		
// 		if(session.getAttribute("id_project")!=null)
// 		{
// 			try
// 			{
// 				String id_project=session.getAttribute("id_project").toString();
// 				idProjectTemp=Integer.parseInt(id_project);
// 			}
// 			catch(Exception e)
// 			{}
// 		}		
// 		else
// 		{
// 			idProjectTemp=CacheUtil.getLastProjectId();
// 		}
// 	}
	
// 	String name="";
// 	if(session.getAttribute("name")!=null)
// 	{
// 		try
// 		{
// 		name=session.getAttribute("name").toString();
		
// 		}
// 		catch(Exception e)
// 		{}
// 	}	
	
// 	String description="";
// 	if(session.getAttribute("description")!=null)
// 	{
// 		try
// 		{
// 			description=session.getAttribute("description").toString();
		
// 		}
// 		catch(Exception e)
// 		{}
// 	}		
	
// 	int idAuthor=Integer.MIN_VALUE;
// 	if(session.getAttribute("id_author")!=null)
// 	{
// 		try
// 		{
// 			String id_author=session.getAttribute("id_author").toString();
// 			idAuthor=Integer.parseInt(id_author);
// 		}
// 		catch(Exception e)
// 		{}
// 	}	
	
// 	int idApprover=Integer.MIN_VALUE;
// 	if(session.getAttribute("id_approver")!=null)
// 	{
// 		try
// 		{
// 			String id_approver=session.getAttribute("id_approver").toString();
// 			idApprover=Integer.parseInt(id_approver);
// 		}
// 		catch(Exception e)
// 		{}
// 	}	
	
// 	String startTime="";
// 	if(session.getAttribute("start_time")!=null)
// 	{
// 		try
// 		{
// 			startTime=session.getAttribute("start_time").toString();
		
// 		}
// 		catch(Exception e)
// 		{}
// 	}	
	
// 	int idVenue=Integer.MIN_VALUE;
// 	if(session.getAttribute("id_venue")!=null)
// 	{
// 		try
// 		{
// 			String id_venue=session.getAttribute("id_venue").toString();
// 			idVenue=Integer.parseInt(id_venue);
// 		}
// 		catch(Exception e)
// 		{}
// 	}	
	
// 	int status=Integer.MIN_VALUE;
// 	if(session.getAttribute("status")!=null)
// 	{
// 		try
// 		{
// 			String status1=session.getAttribute("status").toString();
// 			status=Integer.parseInt(status1);
// 		}
// 		catch(Exception e)
// 		{}
// 	}	
		
		
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Create New Agenda</title>
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/inputForm.css" />
<link rel="stylesheet" href="css/listForm.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-datepicker.css" />
<link rel="stylesheet" href="css/jquery-dialog.css" />

<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.numeric.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.tools.min.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script language="javascript" type="text/javascript">
	$(document).ready(pageLoaded);
	function pageLoaded()
	{
		initDateTimePicker();
		initTooltip();	
		serializeProject();
	} 
	var requiredInputs = [['name','name_required'],['start_time_date','start_time_date_required']];
// 	var intInputs = [];
// 	var doubleInputs = [];
//	var dateInputs = [];
	var timeInputs = [['start_time_date', 'start_time_date_invalid']];

	function checkInputs() {
		var valid = true;

		if (checkRequiredInputs(requiredInputs) == false) {
			valid = false;
		}
// 		if (checkIntInputs(intInputs) == false) {
// 			valid = false;
// 		}
// 		if (checkDoubleInputs(doubleInputs) == false) {
// 			valid = false;
// 		}
// 		if (checkDateInputs(dateInputs, dateFormat) == false) {
// 			valid = false;
// 		}
		if (checkTimeInputsForCorrectFormatOnly(timeInputs) == false) {
			valid = false;
			//alert("Time input: " + valid);
		}

		// SPECIFIC VALIDATE CODE HERE		

		return valid;
	}
// 	function saveIdProject()
// 	{
//   		document.getElementById("hidden_name").value=document.getElementById("name").value;
//   		document.getElementById("hidden_id_project").value=document.getElementById("id_project").value;
//   		document.getElementById("hidden_description").value=document.getElementById("description").value;
//   		document.getElementById("hidden_id_author").value=document.getElementById("id_author").value;
//   		document.getElementById("hidden_id_approver").value=document.getElementById("id_approver").value;
//   		document.getElementById("hidden_start_time").value=document.getElementById("start_time_date").value;
//   		document.getElementById("hidden_id_venue").value=document.getElementById("id_venue").value;
//   		document.getElementById("hidden_status").value=document.getElementById("status").value;
// 		document.idProjectForm.submit();
		alert(idPlace);
		
// 	}
		function serializeProject()
		{
			getCascadeDropdowList('#id_project','#id_event','event');
			
		 	
		}
</script>
</head>
<body>
	<div class="divContainer">
		<%@ include file="menu.jsp"%>
<!-- 				<form id="idProjectForm" name="idProjectForm" action="agenda"  method="get"> -->
<!-- 					<input type="hidden" id="mode" name="mode" value="dependence" /> -->
<!-- 					<input type="hidden" id="hidden_name" name="hidden_name" value="" /> -->
<!-- 					<input type="hidden" id="hidden_id_project" name="hidden_id_project" value="" /> -->
<!-- 					<input type="hidden" id="hidden_description" name="hidden_description" value="" /> -->
<!-- 					<input type="hidden" id="hidden_id_author" name="hidden_id_author" value="" /> -->
<!-- 					<input type="hidden" id="hidden_id_approver" name="hidden_id_approver" value="" /> -->
<!-- 					<input type="hidden" id="hidden_start_time" name="hidden_start_time" value="" /> -->
<!-- 					<input type="hidden" id="hidden_id_venue" name="hidden_id_venue" value="" /> -->
<!-- 					<input type="hidden" id="hidden_status" name="hidden_status" value="" /> -->
<!-- 				</form> -->
				<form id="inputForm" action="agenda?mode=insert<%if(hasProject){%>&id_project=<%=idProject%><%} %>" method="post" onSubmit="return checkInputs();" onreset="return confirm('Do you really want to reset the form?')">
					<table class="tblInput" >
						<% if(hasProject){ %>
							<tr><td colspan="1">
								<b>Project:
									<a id="link_project" name="link_project" href="<%=projectUrl %>"><%=projectName %></a>
								</b>
							</td></tr>
						<% } %>
						<tr>
							<td class="inputHeader">CREATE NEW AGENDA</td>
						</tr>
							<tr>
					<td style="padding-left: 400px; padding-right: 400px;">
						<table cellspacing="0px">
						<% if(!hasProject) { %>
							<tr>
								<td colspan="3">									
										<center><i>(Select project in the below list)</i></center>
								</td>
							</tr>
					
							<tr class="trField">
								<td class="tdFieldName">Project</td>
								<td class="tdFieldInput"><select id="id_project" name="id_project" class="hyjack" onchange="serializeProject();">
										<%=HtmlUtil.genModelSelect(CacheUtil.getProjectList(), null)%>
								</select>
								</td>
								<td class="tdErrMsg"><span id="id_project_required" class="errMsg" style="display: none;">Project is required</span> <span id="id_project_invalid" class="errMsg" style="display: none;">Project is invalid</span>
								</td>
							</tr>
						<% } %>	
					
						<tr class="trField">
							<td class="tdFieldName">Name</td>
							<td class="tdFieldInput"><input class="inputText" title="Name of agenda." type="text" id="name" name="name" maxlength="255"  onblur="validateRequiredInput('name')" />
							</td>
							<td class="tdErrMsg">
								<span id="name_required" class="errMsg" style="display: none;" title="Name is a required field.">(!)</span> 
								<span id="name_invalid" class="errMsg" style="display: none;" title=" ">(!)</span>
							</td>
						</tr>
						
						<tr class="trField">
							<td class="tdFieldName">Event</td>
							<td class="tdFieldInput">
							
							
								<select id="id_event" name="id_event" class="hyjack" title="Choose a event for this agenda.">
								<%if(hasProject) { %>
 								<%=HtmlUtil.<EventModel>genModelSelect(CacheUtil.getEventList(idProject), null)%>
								<% }%>
								</select>
								
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						
						<tr class="trField">
							<td class="tdFieldName">Description</td>
							<td class="tdFieldInput"><textarea id="description" title="Description of the agenda" name="description" rows="5" class="inputTextarea"></textarea>
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Author</td>
							<td class="tdFieldInput"><select id="id_author" name="id_author" class="hyjack">
									<%=HtmlUtil.genModelSelect(CacheUtil.getEmployeeList(), null)%>
							</select> <input class="btnAdd" type="button" id="addNewAuthor" value="" onclick="ajaxAddItemTwoSelectors('#id_author', '#id_approver', 'employee', 'name', 'Please enter new author name!');" title="Click here to add new employee" />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Approver</td>
							<td class="tdFieldInput"><select id="id_approver" name="id_approver" class="hyjack">
									<%=HtmlUtil.genModelSelect(CacheUtil.getEmployeeList(), null, Integer.MIN_VALUE, false, true)%>
							</select> <input type="button" class="btnAdd" id="addNewApproval" value="" onclick="ajaxAddItemTwoSelectors('#id_approver', '#id_author', 'employee', 'name', 'Please enter new approval name!');" title="Click here to add new employee" />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Start Time</td>
							<td class="tdFieldInput"><input type="text" maxlength="19" class="inputDateTime" id="start_time_date" name="start_time_date" title="Click here to choose start time<br/>Note: The format is <b>dd/mm/yyyy at hh:mm</b>"  onblur="validateRequiredInput('start_time_date',true);" onchange="validateDateTimeInput('start_time_date', true);"/> </td>
							<td class="tdErrMsg">
								<span id="start_time_date_required" class="errMsg" style="display: none;" title="Start time is a required field.">(!)</span>
								<span id="start_time_date_invalid" class="errMsg" style="display: none;" title="You've entered an invalid time.<br/>The format should be <b> 'dd/mm/yyyy at hh/mm'</b>">(!)</span>
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Venue</td>
							<td class="tdFieldInput"><select id="id_venue" name="id_venue" class="hyjack">
									<%=HtmlUtil.genModelSelect(CacheUtil.getVenueList(), null)%>
							</select> <input class="btnAdd" type="button" id="addNewIdVenue" value="" onclick="ajaxAddItem('#id_venue', 'venue', 'name', 'Please enter new venue name!');" title="Click to add new venue" /></td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Status</td>
							<td class="tdFieldInput"><select id="status" name="status" title="Choose one status for this agenda" class="hyjack">
									<%=HtmlUtil.genEnumSelect(EnumName.AgendaStatus, null)%>
							</select>
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						
						<tr class="trInputBottom">
						<td class="tdFieldName"></td>
						<td class="tdSubmit">
							<div class="divButtonSubmit" >
								<input class="btnSubmit" type="submit" value="Submit" title="Click to save above information." />
							</div>
							<div class="divButtonReset">
								<input class="btnReset" type="reset" value="Reset" title="Click to reset all above fields." />
							</div>
							<div style="clear: both;">
							</div>
						</td>
									
					</tr>
				</table>
				</td>
			</tr>
		</table>
	</form>
	<%
		String strAgendaListLink = "agendaList.jsp?embedded=true";
	%>
	<jsp:include page="<%=strAgendaListLink%>"></jsp:include>
	</div>
	
</body>
</html>